/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uk.ac.cam.can.generalisator;

import java.util.Random;

/**
 *
 * @author Thomas
 */
public class GenBirthDate implements Generalisator{
    public GenAgeRange g;
    public GenBirthDate(){
        g = new GenAgeRange();
    }
    
    @Override
    public String gen(String value) {
        // is a date transform into age
        if(value.length()==10){
            String splits[] = value.split("-");
            int age = 2012 - (int)(Integer.valueOf(splits[0]));
            return ""+age;
        }else{
            return g.gen(value);
        }
    }

    @Override
    public int getMaxGeneralisation() {
        return 5;
    }

    @Override
    public double getLength(String value) {
        if(value.length()==10)
            return 1.0;
        else{
            return 2.0;
        }
    }
    
    @Override
    public double getMaxLength(){
        return 3.0;
    }

    @Override
    public String getUngeneralisation(String value) {
        Random rand = new Random(System.nanoTime());
        if(value.length()==2){
            int age = Integer.valueOf(value);
            int year = 2012-age;
            int month = rand.nextInt(13);
            int day = rand.nextInt(28);
            return year+"-"+month+"-"+day;
        }else{
            return g.getUngeneralisation(value);
        }
    }

    @Override
    public int getGeneralisationLevel(String value) {
        if(value.length()==10)
            return 1;
        else{
            return 2;
        }
    }
    
}
